﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Oiler
{
    public class SDGraph
    {
        private int Width;
        private int Height;

        public Vector2 Position;
        public Texture2D Pixel;

        public int result;
        public int var;
        public int supply;
        public int demand;


        public void setHeight(int height)
        {
            this.Height = height;
        }

        public void Initialize(Texture2D texture, Vector2 position)
        {
            Pixel = texture;
            Position = position;
            Width = 50;
        }

        public void Update(Player player, int Var)
        {
            int var = Var;
            
            for (int i = 10; i < 1000000; i *= 10)
            {
                supply = (int)player.Supply / i;
                demand = (int)player.Demand / i;

                if (supply < 100 && demand < 100)
                {
                    if (var == 0)
                    {
                        if (supply / 2 > 20 && demand / 2 > 20)
                        {
                            result = (int)(supply / 2);
                            break;
                        }
                        else
                        {
                            result = (int)supply;
                            break;
                        }
                        
                    }

                    if (var == 1)
                    {
                        if (demand / 2 > 20 && supply / 2 > 20)
                        {
                            result = (int)(demand / 2);
                            break;
                        }
                        else
                        {
                            result = (int)demand;
                            break;
                        }
                    }
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 1; i <= result; i++)
            {
                spriteBatch.Draw(Pixel, Position = new Vector2(Position.X, 60 - i), null, Microsoft.Xna.Framework.Color.White, 0f, Vector2.Zero, .5f, SpriteEffects.None, 0f);
            }  
        }
    }
}
